﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;
using Workflows.Components.SchemaUtil.Properties;

namespace Workflows.Components.SchemaUtil
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class CLRScripterComponent:WorkflowComponentBase
    {
        #region ctor
        /// <summary>
        /// 
        /// </summary>
        public CLRScripterComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.Entity_Relations.ToString();
            this.ComponentName = "Linkage";
            this.Description = "Link entities based on table references";
            this.ComponentIcon = Resources.SqlWb_10000;
            this.ComponentImage = Resources.Tool;

            this._Instruction =
                new CLRScripterInstruction(this.ComponentID, Guid.Empty,
                                           "localhost", AuthenticationType.WindowsAuthentication,
                                           Environment.UserDomainName + "\\" + Environment.UserName,
                                           "", string.Empty, string.Empty);
            this._Output=new CLRScripterOutput(this.ComponentID,Guid.Empty,string.Empty);
        }
        #endregion

        #region Overrides of WorkflowComponentBase
        private CLRScripterInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get
            {
                return _Instruction;
            }
            set
            {
                _Instruction = (CLRScripterInstruction)value;
            }
        }

        private CLRScripterOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get
            {
                return _Output;
            }
            set
            {
                _Output = (CLRScripterOutput)value;
            }
        }

        public override XmlNode Serialize(ref System.Xml.XmlDocument xDoc, ref System.Xml.XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(System.Xml.XmlNode xNode)
        {
            CLRScripterComponent component = (CLRScripterComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode);
            return component;
        }
        #endregion
    }
}
